package controllers

import "smart_home/api/device"

type SwitchController struct {
	BaseController
}

// @Title Open
// @Description 打开设备
// @Param	sta		path 	string	true "设备sta"
// @router /open/:sta [get]
func (c *SwitchController) Open() {
	var (
		sta string
		err error
	)
	sta = c.GetString(":sta")
	if err = device.NewSwitch().Act(sta, device.OPEN); err != nil {
		c.Error(err)
		return
	}
	c.Success(nil)
}

// @Title Close
// @Description 关闭设备
// @Param	sta		path 	string	true "设备sta"
// @router /close/:sta [get]
func (c *SwitchController) Close() {
	var (
		sta string
		err error
	)
	sta = c.GetString(":sta")
	if err = device.NewSwitch().Act(sta, device.CLOSE); err != nil {
		c.Error(err)
		return
	}
	c.Success(nil)
}